Fix documenting target-specific dependencies for real
authorAlex Crichton <alex@alexcrichton.com>
Fri, 4 Sep 2015 17:33:11 +0000 (10:33 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 4 Sep 2015 17:33:11 +0000 (10:33 -0700)
It's possible to have multiple dependencies of the same name for a project if a
dependency shows up multiple times as a target-specific dependency. This means
that we can't just find the first one with the relevant name and assume it's the
right one, we instead need to check all of them.

src/cargo/ops/cargo_rustc/context.rs
tests/test_cargo_doc.rs

index 44839f7c9bdaa3d723cd0402763d3896dab08e38..5cfe983593ddc9fdc7eb00f83ed0ab948f1a8f0c 100644 (file)
@@ -417,10 +417,11 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
         let deps = deps.flat_map(|a| a).map(|id| {
             self.get_package(id)
         }).filter(|dep| {
-            let dep = pkg.dependencies().iter().find(|d| {
+            pkg.dependencies().iter().filter(|d| {
                 d.name() == dep.name()
-            }).unwrap();
-            dep.is_transitive() && self.dep_platform_activated(dep, kind)
+            }).any(|dep| {
+                dep.is_transitive() && self.dep_platform_activated(dep, kind)
+            })
         }).filter_map(|dep| {
             dep.targets().iter().find(|t| t.is_lib()).map(|t| (dep, t))
         });
index 5d6d8a90e1f23f51384c0f6ca68fbb967b122305..87dd0ed25415dafe9a277af365b70f014f8d4cc2 100644 (file)
@@ -313,3 +313,37 @@ test!(target_specific_not_documented {
     assert_that(p.cargo_process("doc"),
                 execs().with_status(0));
 });
+
+test!(target_specific_documented {
+    let p = project("foo")
+        .file("Cargo.toml", &format!(r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+
+            [target.foo.dependencies]
+            a = {{ path = "a" }}
+            [target.{}.dependencies]
+            a = {{ path = "a" }}
+        "#, ::rustc_host()))
+        .file("src/lib.rs", "
+            extern crate a;
+
+            /// test
+            pub fn foo() {}
+        ")
+        .file("a/Cargo.toml", r#"
+            [package]
+            name = "a"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("a/src/lib.rs", "
+            /// test
+            pub fn foo() {}
+        ");
+
+    assert_that(p.cargo_process("doc"),
+                execs().with_status(0));
+});